<style scoped>
  .clientSellBill{
    margin-right: 0.5vw;
    padding: 0 15px;
    background-color: white;
    height: 95vh;
    position: relative;
  }
  .csb-top{
    display: flex;
    padding: 1.5vh 0;
    border-bottom: 2px solid #f4f4f4;
  }
  .csb-top p:first-child{
    margin: 3px 6px 0 0;
  }
  .csb-top p:not(:first-child){
    margin: 3px 6px 0 12px;
  }
  .csb-middle{
    padding: 1.5vh 0;
    display: flex;
    justify-content: space-between;
  }
  .csb-middle p{
    margin: 3px 6px 0 0;
  }

  .clientSellBill .footView span{
    float: left;
    margin-right: 20px;
    line-height: 6vh;
    font-size: 14px;
  }
  .clientSellBill .footView span i{
    margin-right: 5px;
  }
  .clientSellBill .summation{
    height: 4vh;
    background-color: #F5F7FA;
  }
  .clientSellBill .summation p{
    line-height: 36px;
    float: right;
  }
</style>

<style>
  .clientSellBill .el-input__icon {
    line-height: 30px;
  }
  .clientSellBill .el-input__inner{
    height: 30px;
  }
  .clientSellBill .csb-top .el-date-editor .el-range__icon{
    line-height: 24px;
  }
  .clientSellBill .csb-top .el-date-editor .el-range-separator{
    line-height: 24px;
    width: 8%;
  }
  .clientSellBill .el-table__footer td {
	height:36px;
}
</style>

<template>
  <div class="clientSellBill">
    <!-- 客户寄卖对账单 -->
    <div class="csb-top">
      <p>客户</p>
      <el-input style="width:60px;margin-right:10px;" v-model="customerNo" @blur="customerNoBlur" :disabled="jxAgent"></el-input>
      <el-select v-model="customerName" @change="e=>{this.customerNo=e;this.customerNoBlur()}" style="width:100px" :disabled="jxAgent">
        <el-option v-for="item in customerList" :key="item.value" :label="item.label" :value="item.value">
          <span style="float:left">{{item.value}}</span>
          <span style="float:right">{{item.label}}</span>
        </el-option>
      </el-select>
      <p>总店编号</p>
      <el-input style="width:160px;" v-model="headquartersNo"></el-input>
      <p>单号</p>
      <el-input style="width:160px;" v-model="sequence"></el-input>
      <p>日期</p>
      <el-date-picker 
        unlink-panels
        v-model="dateList" 
        type="daterange" 
        range-separator="至" 
        start-placeholder="开始日期" 
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd"></el-date-picker>
    </div>
    <div class="csb-middle">
      <div>
        <el-button @click="search" type="primary" icon="el-icon-search">查询</el-button>
        <el-button @click="exportExcel" icon="el-icon-upload2">导出</el-button></div>
      <div style="display:flex;">
        <p>合计</p>
        <el-select v-model="summation" style="width:160px" @change="Change">
          <el-option v-for="item in summationList" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </div>
    </div>
    <el-table 
      :header-cell-style="{background:'#f4f4f4',padding:0,height:'40px'}" 
      :cell-style="{padding:0,height:'36px'}" 
      :data="tableData" 
      height="72vh"
      show-summary 
      :summary-method="getSummaries"
      ref="table"
      style="width: 100%">
      <el-table-column type="index" label="序号" width="50"></el-table-column>
      <template v-for="i in csbList">
        <el-table-column :prop="i.prop" :key="i.prop" :label="i.label" :width="i.width"></el-table-column>
      </template>
    </el-table>
    <div class="summation">
      <p>上期库存数量：{{topInventoryNumber}} 上期库存金额：{{topInventoryMoney}} 上期余额：{{topOverage}} 本期应收：{{thisReceivable}} 本期已收：{{thisReceived}} 本期未收：{{thisUncollected}} 期末库存数量：{{buttonInventoryNumber}} 期末库存金额：{{buttonInventoryMoney}}</p>
    </div>

    <foot-view class="footView" 
      :pagesNum="pagesNum" 
      :hasPagination=true
      :pageSize="limit"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange">
      <div slot="text">
        <el-popover
          placement="top-start"
          width="120"
          max-height="100px"
          trigger="click">
          <el-checkbox-group v-model="selectHeaderList" >
            <el-checkbox 
              v-for="i in headerList" 
              :label="i.value"
              :key="i.value"
              style="margin-bottom:7px"></el-checkbox>
          </el-checkbox-group>
          <i slot="reference" class="el-icon-date">  表头配置</i>
        </el-popover>
        <span>数据库：{{jxQuarter}}</span>
      </div>
    </foot-view>
  </div>
</template>

<script>
import { getClient, customerConsignment } from '../../../network/client'

import footView from '../../../components/FootView'

import table2excel from 'js-table2excel'
import XLSX from "xlsx"

import enterUp from '../../../components/mixins/enterUp'

export default {
  name:'client_sell_bill',
  mixins:[enterUp],
  created(){
    let jxQuarterVal = document.cookie.match(RegExp('jxQuarter' + '=([^;]+)'))
    let jxAgentVal = document.cookie.match(RegExp('jxAgent'+'=([^;]+)'))
    let operatorVal = document.cookie.match(RegExp('jxAgent'+'=([^;]+)'))
    this.jxQuarter = jxQuarterVal ? jxQuarterVal[1] : null
    this.operator = operatorVal ? operatorVal[1] : null
   if(jxAgentVal){
    this.jxAgent = jxAgentVal[1] == 1 ? true : false
   }
    
    this.inpList = this.getInput()
    this.csbList = this.csbList1

    // 获取所有客户信息
    getClient({limit:99999}).then(res => {
      // console.log(res)
      if (res.data.code == 200) {
        let list = res.data.data
        list.forEach(e => {
          if(e.stop != 1){
            this.customerList.push({value:e.no,label:e.name})
          }
        })
        if (this.jxAgent) {
          for (const i of this.customerList) {
            if (i.label == this.operator) {
              this.customerNo = i.value
              this.customerName = i.value
              break
            }
          }
        }
      }
    })
  },
  data(){
    return{
      inpList: [],
      customerNo: '',
      customerName: '',
      customerList: [],
      headquartersNo: '',
      sequence: '',
      dateList: null,

      summation: '不合计',
      summationList:[
        {label:'不合计',value:'不合计'},
        {label:'客户集合',value:'客户集合'},
        {label:'日期集合',value:'日期集合'}
      ],

      tableData:[],
      csbList:[],
      csbList1:[
        {prop:'sequence',label:'单号',width:'120'},
        {prop:'dateTime',label:'日期',width:'100'},
        {prop:'customerName',label:'客户简称',width:'140'},
        {prop:'receivedMoney',label:'已收金额',width:''},
        {prop:'inputNumber',label:'进货数量',width:''},
        {prop:'outNumber',label:'退货数量',width:''},
        {prop:'sellNumber',label:'销货数量',width:''},
        {prop:'sellOutNumber',label:'销退数量',width:''},
        {prop:'inputMoney',label:'进货金额',width:''},
        {prop:'outMoney',label:'退货金额',width:''},
        {prop:'sellOutMoney',label:'销退金额',width:''},
        {prop:'otherIncome',label:'其他应收',width:''},
        {prop:'discountMoney',label:'折让金额',width:''},
      ],
      csbList2:[
        {prop:'customerName',label:'客户简称',width:'140'},
        {prop:'inputNumber',label:'进货数量',width:''},
        {prop:'outNumber',label:'退货数量',width:''},
        {prop:'sellNumber',label:'销货数量',width:''},
        {prop:'sellOutNumber',label:'销退数量',width:''},
        {prop:'buttonInventoryNumber',label:'库存',width:''},
        {prop:'inputMoney',label:'进货金额',width:''},
        {prop:'outMoney',label:'退货金额',width:''},
        {prop:'sellMoney',label:'销货金额',width:''},
        {prop:'sellOutMoney',label:'销退金额',width:''},
        {prop:'buttonInventoryMoney',label:'库存金额',width:''},
        {prop:'otherIncome',label:'其他应收',width:''},
        {prop:'receivedMoney',label:'已收金额',width:''},
        {prop:'discountMoney',label:'折让金额',width:''},
        {prop:'dateTime',label:'日期',width:'120'},
      ],
      csbList3:[
        {prop:'inputNumber',label:'进货数量',width:''},
        {prop:'outNumber',label:'退货数量',width:''},
        {prop:'sellNumber',label:'销货数量',width:''},
        {prop:'sellOutNumber',label:'销退数量',width:''},
        {prop:'inputMoney',label:'进货金额',width:''},
        {prop:'outMoney',label:'退货金额',width:''},
        {prop:'sellMoney',label:'销货金额',width:''},
        {prop:'sellOutMoney',label:'销退金额',width:''},
        {prop:'otherIncome',label:'其他应收',width:''},
        {prop:'receivedMoney',label:'已收金额',width:''},
        {prop:'discountMoney',label:'折让金额',width:''},
        {prop:'dateTime',label:'日期',width:'120'},
      ],

      notTotal: [],
      byCustomerMap: [],
      byTimeMap: [],

      buttonInventoryMoney: 0,
      buttonInventoryNumber: 0,
      thisReceivable: 0,
      thisReceived: 0,
      thisUncollected: 0,
      topInventoryMoney: 0,
      topInventoryNumber: 0,
      topOverage: 0,

      // 总数据条数
      dataLen: 0,
      // 总页码
      pagesNum: 0,
      // 分页条数
      limit: 20,
      // 当前页码
      currentPage: 1,
      jxQuarter: null,
      jxAgent:null,
      operator:null,

      // jxQuarter: document.cookie.match(RegExp('jxQuarter'+'=([^;]+)'))[1],
      // jxAgent: document.cookie.match(RegExp('jxAgent'+'=([^;]+)'))[1] == 1 ? true : false,
      // operator: document.cookie.match(RegExp('jxUser'+'=([^;]+)'))[1],

      // 表头
      selectHeaderList: [],
      headerList: [],

      summationData: {}
    }
  },
  watch: {
    customerNo(a,b){
      this.customerNo = a.toUpperCase().trim()
    },
    headquartersNo(a,b){
      this.headquartersNo = a.toUpperCase().trim()
    },
    sequence(a,b){
      this.sequence = a.toUpperCase().trim()
    },
    dataLen(a,b){
      this.pagesNum = Math.ceil(this.dataLen / this.limit)
    },
    limit(a,b){
      this.pagesNum = Math.ceil(this.dataLen / this.limit)
    }
  },
  methods:{
    Change(e){
      this.currentPage = 1
      this.tableTypeChange = !this.tableTypeChange
      switch (e) {
        case '不合计':
          this.summationData.receivedMoney = 0
          this.summationData.inputNumber = 0
          this.summationData.inputMoney = 0
          this.summationData.outNumber = 0
          this.summationData.outMoney = 0
          this.summationData.sellNumber = 0
          this.summationData.sellOutNumber = 0
          this.summationData.sellOutMoney = 0
          this.summationData.otherIncome = 0
          this.summationData.discountMoney = 0

          this.notTotal.forEach(e => {
            this.summationData.receivedMoney += Number(e.receivedMoney)
            this.summationData.inputNumber += Number(e.inputNumber)
            this.summationData.inputMoney += Number(e.inputMoney)
            this.summationData.outNumber += Number(e.outNumber)
            this.summationData.outMoney += Number(e.outMoney)
            this.summationData.sellNumber += Number(e.sellNumber)
            this.summationData.sellOutNumber += Number(e.sellOutNumber)
            this.summationData.sellOutMoney += Number(e.sellOutMoney)
            this.summationData.otherIncome += Number(e.otherIncome)
            this.summationData.discountMoney += Number(e.discountMoney)
          })
          this.csbList = this.csbList1
          this.dataLen = this.notTotal.length
          this.tableData = this.notTotal.slice(0,this.limit)
          break;
        case '客户集合':
          this.summationData.receivedMoney = 0
          this.summationData.inputNumber = 0
          this.summationData.inputMoney = 0
          this.summationData.outNumber = 0
          this.summationData.outMoney = 0
          this.summationData.sellNumber = 0
          this.summationData.sellOutNumber = 0
          this.summationData.sellOutMoney = 0
          this.summationData.otherIncome = 0
          this.summationData.discountMoney = 0
          this.summationData.sellMoney = 0
          this.summationData.buttonInventoryNumber = 0
          this.summationData.buttonInventoryMoney = 0

          this.notTotal.forEach(e => {
            this.summationData.receivedMoney += Number(e.receivedMoney)
            this.summationData.inputNumber += Number(e.inputNumber)
            this.summationData.inputMoney += Number(e.inputMoney)
            this.summationData.outNumber += Number(e.outNumber)
            this.summationData.outMoney += Number(e.outMoney)
            this.summationData.sellNumber += Number(e.sellNumber)
            this.summationData.sellOutNumber += Number(e.sellOutNumber)
            this.summationData.sellOutMoney += Number(e.sellOutMoney)
            this.summationData.otherIncome += Number(e.otherIncome)
            this.summationData.discountMoney += Number(e.discountMoney)
            this.summationData.sellMoney += Number(e.sellMoney)
            this.summationData.buttonInventoryNumber += Number(e.buttonInventoryNumber)
            this.summationData.buttonInventoryMoney += Number(e.buttonInventoryMoney)
          })
          this.csbList = this.csbList2
          this.dataLen = this.byCustomerMap.length
          this.tableData = this.byCustomerMap.slice(0,this.limit)
          break;
        case '日期集合':
          this.summationData.receivedMoney = 0
          this.summationData.inputNumber = 0
          this.summationData.inputMoney = 0
          this.summationData.outNumber = 0
          this.summationData.outMoney = 0
          this.summationData.sellNumber = 0
          this.summationData.sellOutNumber = 0
          this.summationData.sellOutMoney = 0
          this.summationData.otherIncome = 0
          this.summationData.discountMoney = 0
          this.summationData.sellMoney = 0
          this.summationData.buttonInventoryNumber = 0
          this.summationData.buttonInventoryMoney = 0

          this.notTotal.forEach(e => {
            this.summationData.receivedMoney += Number(e.receivedMoney)
            this.summationData.inputNumber += Number(e.inputNumber)
            this.summationData.inputMoney += Number(e.inputMoney)
            this.summationData.outNumber += Number(e.outNumber)
            this.summationData.outMoney += Number(e.outMoney)
            this.summationData.sellNumber += Number(e.sellNumber)
            this.summationData.sellOutNumber += Number(e.sellOutNumber)
            this.summationData.sellOutMoney += Number(e.sellOutMoney)
            this.summationData.otherIncome += Number(e.otherIncome)
            this.summationData.discountMoney += Number(e.discountMoney)
            this.summationData.sellMoney += Number(e.sellMoney)
            this.summationData.buttonInventoryNumber += Number(e.buttonInventoryNumber)
            this.summationData.buttonInventoryMoney += Number(e.buttonInventoryMoney)
          })
          
          this.csbList = this.csbList3
          this.dataLen = this.byTimeMap.length
          this.tableData = this.byTimeMap.slice(0,this.limit)
          break;
      }
      this.$forceUpdate()
    },
    search(){
      let params = {
        customerNo: this.customerNo,
        headquartersNo: this.headquartersNo,
        sequence: this.sequence,
        startTime: this.dateList ? this.dateList[0] + ' 00:00:00' : '',
        endTime: this.dateList ? this.dateList[1] + ' 23:59:59' : ''
      }
      customerConsignment(params).then(res => {
        // console.log(res)
        this.notTotal = []
        this.byTimeMap = []
        this.byCustomerMap = []
        this.tableData = []

        this.buttonInventoryMoney = 0
        this.buttonInventoryNumber = 0
        this.thisReceivable = 0
        this.thisReceived = 0
        this.thisUncollected = 0
        this.topInventoryMoney = 0
        this.topInventoryNumber = 0
        this.topOverage = 0
        if (res.data.code == 200) {
          this.notTotal = res.data.data.customerConsignmentReconciliationOneVOList || []
          this.byTimeMap = res.data.data.byTimeMap || []
          this.byCustomerMap = res.data.data.byCustomerMap || []

          let tmpData = res.data.data.customerConsignmentReconciliationTwoVO
          this.buttonInventoryMoney = tmpData.buttonInventoryMoney
          this.buttonInventoryNumber = tmpData.buttonInventoryNumber 
          this.thisReceivable = tmpData.thisReceivable 
          this.thisReceived = tmpData.thisReceived 
          this.thisUncollected = tmpData.thisUncollected
          this.topInventoryMoney = tmpData.topInventoryMoney 
          this.topInventoryNumber = tmpData.topInventoryNumber 
          this.topOverage = tmpData.topOverage 
          
          this.Change(this.summation)
          this.zero2blank()

          this.$nextTick(() => {
            this.$refs.table.doLayout()
          })
        } else {
          this.$message.info("暂无数据")
        }
      })
    },
    // 导出
    exportExcel(){
      let column = []

      let header = {}
      let data = {}
      let index = 2
      let output = {}
      let ref = ''
      let merges = []
      let wb = {}
      switch (this.summation) {
        case '不合计':
          header = {
            A1: {v: '单号'},
            B1: {v: '日期'},
            C1: {v: '客户简称'},
            D1: {v: '已收金额'},
            E1: {v: '进货数量'},
            F1: {v: '退货数量'},
            G1: {v: '销货数量'},
            H1: {v: '销退数量'},
            I1: {v: '进货金额'},
            J1: {v: '退货金额'},
            K1: {v: '销退金额'},
            L1: {v: '其他应收'},
            M1: {v: '折让金额'}
          }

          //表格数据
          this.notTotal.forEach(e => {
            data['A'+index] = {v:e.sequence}
            data['B'+index] = {v:e.dateTime}
            data['C'+index] = {v:e.customerName}
            data['D'+index] = {v:e.receivedMoney}
            data['E'+index] = {v:e.inputNumber}
            data['F'+index] = {v:e.outNumber}
            data['G'+index] = {v:e.sellNumber}
            data['H'+index] = {v:e.sellOutNumber}
            data['I'+index] = {v:e.inputMoney}
            data['J'+index] = {v:e.outMoney}
            data['K'+index] = {v:e.sellOutMoney}
            data['L'+index] = {v:e.otherIncome}
            data['M'+index] = {v:e.discountMoney}
            index++
          })

          data['A'+index] = {v:'合计：'}
          data['D'+index] = {v:this.summationData.receivedMoney}
          data['E'+index] = {v:this.summationData.inputNumber}
          data['F'+index] = {v:this.summationData.outNumber}
          data['G'+index] = {v:this.summationData.sellNumber}
          data['H'+index] = {v:this.summationData.sellOutNumber}
          data['I'+index] = {v:this.summationData.inputMoney}
          data['J'+index] = {v:this.summationData.outMoney}
          data['K'+index] = {v:this.summationData.sellOutNumber}
          data['L'+index] = {v:this.summationData.otherIncome}
          data['M'+index] = {v:this.summationData.discountMoney}
          index++

          data['A'+index] = {v:'上期库存数量'}
          data['B'+index] = {v:this.topInventoryNumber}
          data['C'+index] = {v:'上期库存金额'}
          data['D'+index] = {v:this.topInventoryMoney}
          data['E'+index] = {v:'上期余额'}
          data['F'+index] = {v:this.topOverage}
          index++

          data['A'+index] = {v:'本期应收'}
          data['B'+index] = {v:this.thisReceivable}
          data['C'+index] = {v:'本期已收'}
          data['D'+index] = {v:this.thisReceived}
          data['E'+index] = {v:'本期未收'}
          data['F'+index] = {v:this.thisUncollected}

          index++
          data['A'+index] = {v:'期末库存数量'}
          data['B'+index] = {v:this.buttonInventoryNumber}
          data['C'+index] = {v:'期末库存金额'}
          data['D'+index] = {v:this.buttonInventoryMoney}

          // 合并 headers 和 data
          output = Object.assign({}, header, data);
          // 表格范围，范围越大生成越慢 
          ref = 'A1:M' + (this.notTotal.length + 10)
          //合并单元格设置
          merges = []
          // 构建 workbook 对象
          wb = {
            SheetNames: ['客户寄卖对账单'],
            Sheets: {
              '客户寄卖对账单': Object.assign({}, output, { '!ref': ref, '!merges': merges })
            }
          }
          // 导出 Excel
          XLSX.writeFile(wb, '客户寄卖对账单不合计.xlsx')
          return
          column = [
            {key:'sequence',title:'单号',type: 'text'},
            {key:'dateTime',title:'日期',type: 'text'},
            {key:'customerName',title:'客户简称',type: 'text'},
            {key:'receivedMoney',title:'已收金额',type: 'text'},
            {key:'inputNumber',title:'进货数量',type: 'text'},
            {key:'outNumber',title:'退货数量',type: 'text'},
            {key:'sellNumber',title:'销货数量',type: 'text'},
            {key:'sellOutNumber',title:'销退数量',type: 'text'},
            {key:'inputMoney',title:'进货金额',type: 'text'},
            {key:'outMoney',title:'退货金额',type: 'text'},
            {key:'sellOutMoney',title:'销退金额',type: 'text'},
            {key:'otherIncome',title:'其他应收',type: 'text'},
            {key:'discountMoney',title:'折让金额',type: 'text'},
          ]
          table2excel(column, this.notTotal, "客户寄卖对账单不合计.xls")
          break;
        case '客户集合':
          header = {
            A1: {v: '客户简称'},
            B1: {v: '进货数量'},
            C1: {v: '退货数量'},
            D1: {v: '销货数量'},
            E1: {v: '销退数量'},
            F1: {v: '库存'},
            G1: {v: '进货金额'},
            H1: {v: '退货金额'},
            I1: {v: '销货金额'},
            J1: {v: '销退金额'},
            K1: {v: '库存金额'},
            L1: {v: '其他应收'},
            M1: {v: '已收金额'},
            N1: {v: '折让金额'},
            O1: {v: '日期'}
          }
          
          //表格数据
          this.byCustomerMap.forEach(e => {
            data['A'+index] = {v:e.customerName}
            data['B'+index] = {v:e.inputNumber}
            data['C'+index] = {v:e.outNumber}
            data['D'+index] = {v:e.sellNumber}
            data['E'+index] = {v:e.sellOutNumber}
            data['F'+index] = {v:e.buttonInventoryNumber}
            data['G'+index] = {v:e.inputMoney}
            data['H'+index] = {v:e.outMoney}
            data['I'+index] = {v:e.sellMoney}
            data['J'+index] = {v:e.sellOutMoney}
            data['K'+index] = {v:e.buttonInventoryMoney}
            data['L'+index] = {v:e.otherIncome}
            data['M'+index] = {v:e.receivedMoney}
            data['N'+index] = {v:e.discountMoney}
            data['O'+index] = {v:e.dateTime}
            index++
          })

          data['A'+index] = {v:'合计：'}
          data['B'+index] = {v:this.summationData.inputNumber}
          data['C'+index] = {v:this.summationData.outNumber}
          data['D'+index] = {v:this.summationData.sellNumber}
          data['E'+index] = {v:this.summationData.sellOutNumber}
          data['F'+index] = {v:this.summationData.buttonInventoryNumber}
          data['G'+index] = {v:this.summationData.inputMoney}
          data['H'+index] = {v:this.summationData.outMoney}
          data['I'+index] = {v:this.summationData.sellMoney}
          data['J'+index] = {v:this.summationData.sellOutMoney}
          data['K'+index] = {v:this.summationData.buttonInventoryMoney}
          data['L'+index] = {v:this.summationData.otherIncome}
          data['M'+index] = {v:this.summationData.receivedMoney}
          data['N'+index] = {v:this.summationData.discountMoney}
          data['O'+index] = {v:this.summationData.dateTime}
          index++

          data['A'+index] = {v:'上期库存数量'}
          data['B'+index] = {v:this.topInventoryNumber}
          data['C'+index] = {v:'上期库存金额'}
          data['D'+index] = {v:this.topInventoryMoney}
          data['E'+index] = {v:'上期余额'}
          data['F'+index] = {v:this.topOverage}
          index++

          data['A'+index] = {v:'本期应收'}
          data['B'+index] = {v:this.thisReceivable}
          data['C'+index] = {v:'本期已收'}
          data['D'+index] = {v:this.thisReceived}
          data['E'+index] = {v:'本期未收'}
          data['F'+index] = {v:this.thisUncollected}

          index++
          data['A'+index] = {v:'期末库存数量'}
          data['B'+index] = {v:this.buttonInventoryNumber}
          data['C'+index] = {v:'期末库存金额'}
          data['D'+index] = {v:this.buttonInventoryMoney}

          // 合并 headers 和 data
          output = Object.assign({}, header, data)
          // 表格范围，范围越大生成越慢 
          ref = 'A1:O' + (this.byCustomerMap.length + 10)
          //合并单元格设置
          merges = []
          // 构建 workbook 对象
          wb = {
            SheetNames: ['客户寄卖对账单'],
            Sheets: {
              '客户寄卖对账单': Object.assign({}, output, { '!ref': ref, '!merges': merges })
            }
          }
          // 导出 Excel
          XLSX.writeFile(wb, '客户寄卖对账单客户集合.xlsx')
          return
          column = [
            {key:'customerName',title:'客户简称',type: 'text'},
            {key:'inputNumber',title:'进货数量',type: 'text'},
            {key:'outNumber',title:'退货数量',type: 'text'},
            {key:'sellNumber',title:'销货数量',type: 'text'},
            {key:'sellOutNumber',title:'销退数量',type: 'text'},
            {key:'buttonInventoryNumber',title:'库存',type: 'text'},
            {key:'inputMoney',title:'进货金额',type: 'text'},
            {key:'outMoney',title:'退货金额',type: 'text'},
            {key:'sellMoney',title:'销货金额',type: 'text'},
            {key:'sellOutMoney',title:'销退金额',type: 'text'},
            {key:'buttonInventoryMoney',title:'库存金额',type: 'text'},
            {key:'otherIncome',title:'其他应收',type: 'text'},
            {key:'receivedMoney',title:'已收金额',type: 'text'},
            {key:'discountMoney',title:'折让金额',type: 'text'},
            {key:'dateTime',title:'日期',type: 'text'}
          ]
          table2excel(column, this.byCustomerMap, "客户寄卖对账单客户集合.xls")
          break;
        case '日期集合':
          header = {
            A1: {v: '日期'},
            B1: {v: '进货数量'},
            C1: {v: '退货数量'},
            D1: {v: '销货数量'},
            E1: {v: '销退数量'},
            F1: {v: '进货金额'},
            G1: {v: '退货金额'},
            H1: {v: '销货金额'},
            I1: {v: '销退金额'},
            J1: {v: '其他应收'},
            K1: {v: '已收金额'},
            L1: {v: '折让金额'}
          }
          
          //表格数据
          this.byTimeMap.forEach(e => {
            data['A'+index] = {v:e.dateTime}
            data['B'+index] = {v:e.inputNumber}
            data['C'+index] = {v:e.outNumber}
            data['D'+index] = {v:e.sellNumber}
            data['E'+index] = {v:e.sellOutNumber}
            data['F'+index] = {v:e.inputMoney}
            data['G'+index] = {v:e.outMoney}
            data['H'+index] = {v:e.sellMoney}
            data['I'+index] = {v:e.sellOutMoney}
            data['J'+index] = {v:e.otherIncome}
            data['K'+index] = {v:e.receivedMoney}
            data['L'+index] = {v:e.discountMoney}
            index++
          })

          data['A'+index] = {v:'合计：'}
          data['B'+index] = {v:this.summationData.inputNumber}
          data['C'+index] = {v:this.summationData.outNumber}
          data['D'+index] = {v:this.summationData.sellNumber}
          data['E'+index] = {v:this.summationData.sellOutNumber}
          data['F'+index] = {v:this.summationData.inputMoney}
          data['G'+index] = {v:this.summationData.outMoney}
          data['H'+index] = {v:this.summationData.sellMoney}
          data['I'+index] = {v:this.summationData.sellOutMoney}
          data['J'+index] = {v:this.summationData.otherIncome}
          data['K'+index] = {v:this.summationData.receivedMoney}
          data['L'+index] = {v:this.summationData.discountMoney}
          index++

          data['A'+index] = {v:'上期库存数量'}
          data['B'+index] = {v:this.topInventoryNumber}
          data['C'+index] = {v:'上期库存金额'}
          data['D'+index] = {v:this.topInventoryMoney}
          data['E'+index] = {v:'上期余额'}
          data['F'+index] = {v:this.topOverage}
          index++

          data['A'+index] = {v:'本期应收'}
          data['B'+index] = {v:this.thisReceivable}
          data['C'+index] = {v:'本期已收'}
          data['D'+index] = {v:this.thisReceived}
          data['E'+index] = {v:'本期未收'}
          data['F'+index] = {v:this.thisUncollected}

          index++
          data['A'+index] = {v:'期末库存数量'}
          data['B'+index] = {v:this.buttonInventoryNumber}
          data['C'+index] = {v:'期末库存金额'}
          data['D'+index] = {v:this.buttonInventoryMoney}

          // 合并 headers 和 data
          output = Object.assign({}, header, data)
          // 表格范围，范围越大生成越慢 
          ref = 'A1:L' + (this.byTimeMap.length + 10)
          //合并单元格设置
          merges = []
          // 构建 workbook 对象
          wb = {
            SheetNames: ['客户寄卖对账单'],
            Sheets: {
              '客户寄卖对账单': Object.assign({}, output, { '!ref': ref, '!merges': merges })
            }
          }
          // 导出 Excel
          XLSX.writeFile(wb, '客户寄卖对账单日期集合.xlsx')
          return
          column = [
            {key:'inputNumber',title:'进货数量',type: 'text'},
            {key:'outNumber',title:'退货数量',type: 'text'},
            {key:'sellNumber',title:'销货数量',type: 'text'},
            {key:'sellOutNumber',title:'销退数量',type: 'text'},
            {key:'inputMoney',title:'进货金额',type: 'text'},
            {key:'outMoney',title:'退货金额',type: 'text'},
            {key:'sellMoney',title:'销货金额',type: 'text'},
            {key:'sellOutMoney',title:'销退金额',type: 'text'},
            {key:'otherIncome',title:'其他应收',type: 'text'},
            {key:'receivedMoney',title:'已收金额',type: 'text'},
            {key:'discountMoney',title:'折让金额',type: 'text'},
            {key:'dateTime',title:'日期',type: 'text'}
          ]
          table2excel(column, this.byTimeMap, "客户寄卖对账单日期集合.xls")
          break;
      }
    },
    // 客户编号失去焦点
    customerNoBlur(){
      if (this.customerNo != '') {
        for (const i of this.customerList) {
          if (this.customerNo == i.value) {
            this.customerName = i.label
            return
          }
        }
        this.$alert('无此客户编号', '', {
          confirmButtonText: '确定'
        })
        this.customerNo = ''
        this.customerName = ''
      } else {
        this.customerName = ''
      }
    },

    // 每页显示页数改变
    handleSizeChange(val){
      this.limit = val
      switch (this.summation) {
        case '不合计':
          this.tableData = this.notTotal.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          break;
        case '客户集合':
          this.tableData = this.byCustomerMap.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          break;
        case '日期集合':
          this.tableData = this.byTimeMap.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          break;
      }
    },
    // 当前页改变
    handleCurrentChange(val){
      this.currentPage = val
      switch (this.summation) {
        case '不合计':
          this.tableData = this.notTotal.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          break;
        case '客户集合':
          this.tableData = this.byCustomerMap.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          break;
        case '日期集合':
          this.tableData = this.byTimeMap.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          break;
      }
    },

    getSummaries(param){
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        const prop = column.property
        switch (prop) {
          case 'discountMoney':
            sums[index] = this.summationData.discountMoney || ''
            break;
          case 'inputMoney':
            sums[index] = this.summationData.inputMoney || ''
            break;
          case 'outMoney':
            sums[index] = this.summationData.outMoney || ''
            break;
          case 'inputNumber':
            sums[index] = this.summationData.inputNumber || ''
            break;
          case 'outNumber':
            sums[index] = this.summationData.outNumber || ''
            break;
          case 'sellNumber':
            sums[index] = this.summationData.sellNumber || ''
            break;
          case 'receivedMoney':
            sums[index] = this.summationData.receivedMoney || ''
            break;
          case 'sellOutNumber':
            sums[index] = this.summationData.sellOutNumber || ''
            break;
          case 'sellOutMoney':
            sums[index] = this.summationData.sellOutMoney || ''
            break;
          case 'otherIncome':
            sums[index] = this.summationData.otherIncome || ''
            break;
          case 'sellMoney':
            sums[index] = this.summationData.sellMoney || ''
            break;
          case 'buttonInventoryNumber':
            sums[index] = this.summationData.buttonInventoryNumber || ''
            break;
          case 'buttonInventoryMoney':
            sums[index] = this.summationData.buttonInventoryMoney || ''
            break;
        }
        let decimal = sums[index] ? sums[index].toString().split('.')[1] : ''
        if (decimal && decimal.length > 2) {
          sums[index] = sums[index].toFixed(2)
        }
      })
      return sums
    },

    zero2blank(){
      let list = [
        this.notTotal,
        this.byTimeMap,
        this.byCustomerMap
      ]
      
      list.forEach(f => {
        // console.log(f)
        f.forEach(e => {
          for (const key in e) {
            if (Object.hasOwnProperty.call(e, key)) {
              const element = e[key];
              if (element == 0) e[key] = ''
            }
          }
        });
      });
    }
  },
  components: {
    footView
  },
}
</script>